#include "protocol.hpp"

void TestRequest()
{
    //序列化
    Request req(10, 10, '+');
    std::string pakeage;
    req.serialize(&pakeage);
    std::cout << pakeage << std::endl;
    std::string content;
    Encode(pakeage, &content);
    std::cout << content << std::endl;

    //去报头
    Decode(content);
    std::cout << content << std::endl;
    //反序列化
    req.Deserialize(content);

    std::cout << req.x << std::endl;
    std::cout << req.op << std::endl;
    std::cout << req.y << std::endl;
}

void Testresponse()
{
    Response rsp(10, 0);

    //序列化 "10 0"
    std::string pakeage;
    rsp.serialize(&pakeage);
    std::cout << pakeage << std::endl;
    std::string content;
    //封装报头 "4""10 0"
    Encode(pakeage, &content);
    std::cout << content << std::endl;

    //去报头
    Decode(content);
    std::cout << content << std::endl;
    //反序列化
    rsp.Deserialize(content);
    std::cout << content << std::endl;

    std::cout << rsp.result << std::endl;
    std::cout << rsp.code << std::endl;
}


int main()
{
    // TestRequest();

    Testresponse();
    return 0;
}